package com.nhic.blog.service;

import com.nhic.blog.Utils.MD5Util;
import com.nhic.blog.po.User;
import com.nhic.blog.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserRepository userRepository;
    @Override
    public User checkUser(String username, String password) {
        User user = userRepository.findByUsernameAndPassword(username, MD5Util.md5Password(password));
        return user;
    }

    @Override
    public User updatePwd(User user) {
        User u = userRepository.findByUsernameAndPassword(user.getUsername(), MD5Util.md5Password(user.getPassword()));
        u.setPassword(MD5Util.md5Password(user.getNewpassword()));
        User save = userRepository.save(u);
        return save;
    }
}
